Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Find more types using Type Inference #27

Merged
merged 1 commit into from
Mar 20, 2018
Merged

Find more types using Type Inference #27

merged 1 commit into from
Mar 20, 2018

Conversation

urish
Copy link
Collaborator

@urish urish commented Mar 9, 2018

Many times, TypeScript can infer the types of arguments you pass in a function call by looking at their definition. Consider the following example:

const promise = Promise.resolve(15);
f(promise);

In this case, TypeScript can infer the type of promise as Promise<number>. We can take advantage of this information to add type information to the first parameter of f. So given the following code as input:

function f(a) {
  return a;
}

const promise = Promise.resolve(15);
f(promise);

We should be able to discover the type of argument a correctly, and get the following result:

function f(a: Promise<number>) {
  return a;
}

const promise = Promise.resolve(15);
f(promise);

This PR adds experimental support for this feature. At this time, the code is still work-in-progress and is not yet ready to be merged.

@urish urish added the enhancement New feature or request label Mar 9, 2018
@urish urish self-assigned this Mar 9, 2018
Repository owner deleted a comment from coveralls Mar 9, 2018
@urish urish changed the title Find more types using Type Inference [WIP] Find more types using Type Inference Mar 20, 2018
@urish urish merged commit 74e24df into master Mar 20, 2018
@zoehneto zoehneto mentioned this pull request Mar 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant